﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System.Threading;

namespace System.Threading
{
    public static class ThreadExtention
    {
        /// <summary>
        /// 延迟调用方法，主要是用来模拟网络延迟等测试工作
        /// </summary>
        /// <param name="time"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static async Task LazyInvok(TimeSpan time, Action action)
        {
            var task = new System.Threading.Tasks.TaskCompletionSource<object>();
            ThreadPoolTimer.CreateTimer((timer) =>
            {
                if (action != null)
                    action();
                task.SetResult(null);
            }, time);
            await task.Task;
        }
    }
}
